package com.wb3.meta.api.core.controller;

import com.wb3.meta.api.core.service.UsersService;
import com.wb3.meta.api.core.vo.ReqUsersVo;
import com.wb3.meta.api.core.vo.ResUsersVo;
import com.wb3.meta.common.annotation.NoPermission;
import com.wb3.meta.common.annotation.RequireAuth;
import com.wb3.meta.common.plugin.BaseResultController;
import com.wb3.meta.common.pojo.ResultT;
import com.wb3.meta.common.utils.IPUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@RestController
@Api(tags = "用户相关接口")
@RequestMapping("base/user")
public class UsersController extends BaseResultController<ReqUsersVo> {

    @Autowired
    private UsersService userService;

    /**
     * 列表接口
     *
     * @param reqUsersVo
     */
    @NoPermission
    @Override
    @ApiOperation("列表接口")
    @GetMapping("list")
    public ResultT list(ReqUsersVo reqUsersVo) {
        return userService.getModelMapPage(reqUsersVo);
    }


    /**
     * 明细接口
     *
     * @param reqUsersVo
     */
    @RequireAuth
    @Override
    @ApiOperation("详情接口")
    @GetMapping("detail")
    public ResultT detail(ReqUsersVo reqUsersVo) {
        return userService.getModelMapById(reqUsersVo.getId());
    }

    /**
     * 新增or更新接口
     *
     * @param reqUsersVo
     */
    @RequireAuth
    @Override
    @ApiOperation("更新接口")
    @PostMapping("update")
    public ResultT saveOrUpdate(@RequestBody ReqUsersVo reqUsersVo) {
        return userService.saveOrUpdate(reqUsersVo);
    }

    /**
     * 删除接口
     *
     * @param reqUsersVo
     */
    @NoPermission
    @Override
    @ApiOperation("删除接口")
    @PostMapping("delete")
    public ResultT delete(@RequestBody ReqUsersVo reqUsersVo) {
        return userService.delete(reqUsersVo);
    }



}
